{extend name="admin@publics/base"/}
{block name="title"}角色管理{/block}
{block name="body"}
<script>
//页面变量
_PAGE['adminAuthGroup'] = {
};
/*==========控制器==========*/
Ext.define('admin.auth_group.CURDViewController', {
	extend: 'Tg.tx.CURDViewController',
	alias: 'controller._adminAuthGroupController',
    //行_权限
    _ColumnRule:function(_Grid, _Rindex, _Cindex) {
		var _Me	= this;
		var _V	= _Me.getView();
		var _VM	= _V.getViewModel();
		var _Store	= _VM.get('_MainStore');
		var _Grid	= _V.down('admin_AuthGroup_rules');
		var _Store2 = _Grid.getStore();
		var _Url = _VM.get('_Url.rules');
		var _Pk = _VM.get('_Pk');
        var _Select = _Store.getAt(_Rindex);
		var _Params={};
		_Params[_Pk]=_Select.get(_Pk);
        Ext.apply(_Store2.proxy.extraParams, _Params);
		_Store2.reload();
    },
	//权限 - 保存
	_EditRule:function(_Btn) {
		var _Me	= this;
		var _V	= _Me.getView();
		var _VM	= _V.getViewModel();
		var _Store = _VM.get('_RulesStore');
		var _Url = _VM.get('_Url.rules');
		var _Pk = _VM.get('_Pk');
		var _Params= _Store['proxy']['extraParams'];
		if(!_Params.hasOwnProperty("id")){
			Ext.Msg.alert('错误', '尚未选择角色，禁止提交');
			return ;
		}
		var _Id			= _Params['id'];
        if(parseInt(_Id) < 1 || _Id == undefined){
			Ext.Msg.alert('错误', '角色标识错误，禁止提交');
		}
		var _Data		= _Btn.up('admin_AuthGroup_rules').getChecked();
		var _Rules		= [];
		for (var k = 0; k < _Data.length; k++) {
			_Rules.push(_Data[k]['data']['id']);
		}
		_Rules = _Rules.join(",");
		var _Params={};
		_Params[_Pk]=_Id;
		_Params['rules']=_Rules;
        var _Return	= Ext.create('Tg.tx.Action').doAction({params:_Params,url:_Url});
	}
});
/*==========模型==========*/
Ext.define('admin.auth_group.CURDViewModel', {
	extend: 'Tg.tx.CURDViewModel',
	alias: 'viewmodel._adminAuthGroupViewModel',
    //Data
    data:{
    	//权限
        _Auth:{
        	index	: {if condition="_CheckAuth('admin/AuthGroup/index')"}true{else/}false{/if},
        	add		: {if condition="_CheckAuth('admin/AuthGroup/add')"}true{else/}false{/if},
        	edit	: {if condition="_CheckAuth('admin/AuthGroup/edit')"}true{else/}false{/if},
        	del		: {if condition="_CheckAuth('admin/AuthGroup/del')"}true{else/}false{/if},
        	rules	: {if condition="_CheckAuth('admin/AuthGroup/rules')"}true{else/}false{/if},
        },
        _Url:{
        	index	: _PATH['site']+'/admin/auth_group/index',
        	add		: _PATH['site']+'/admin/auth_group/add',
        	edit	: _PATH['site']+'/admin/auth_group/edit',
        	del		: _PATH['site']+'/admin/auth_group/del',
        	rules	: _PATH['site']+'/admin/auth_group/rules',
        },
        //操作视图
        _Ext:{
        	index	: 'admin.auth_group.index',
        	serch	: 'admin.auth_group.serch',
        	add		: 'admin.auth_group.updata',
        	edit	: 'admin.auth_group.updata',
        	look	: 'admin.auth_group.look',
        },
    },
    //Store
	stores: {
		_MainStore: {
			type: 'tree',
			sorters: [{property: 'id',direction: 'desc'}],
			remoteSort: true,
			remoteFilter:true,
			expanded:true,
			proxy: {
				type: 'ajax',
				api: {read: _PATH['site']+'/admin/auth_group/index'},
				actionMethods:{read: "POST"},
				reader: {type: 'json',root: 'children'}
			},
		},
        _RulesStore: {
        	type: 'tree',
			sorters: [{property: 'sort',direction: 'asc'}],
			remoteSort: true,
			remoteFilter:true,
			expanded:true,
			proxy: {
				type: 'ajax',
				api: {read: _PATH['site']+'/admin/auth_group/rules'},
				actionMethods:{read: "GET"},
				reader: {type: 'json',root: 'children'}
			},
		}
	},
});
/*==========视图==========*/
Ext.define('admin.auth_group.index', {
	extend: 'Tg.tx.CURDList',
	alias: 'widget.admin_AuthGroup_index',
	requires: [
		'admin.auth_group.CURDViewController',
		'admin.auth_group.CURDViewModel',
	],
	controller: '_adminAuthGroupController',
	viewModel: '_adminAuthGroupViewModel',
    _TbarLBefore:[
        {xtype: 'label',text: '节点管理',itemId:'_Tit',style: 'font-size:16px; padding-right:10px;margin-right: 10px;border-right: dotted 1px #ccc;'},
    ],
	layout:'border',
    items:[
		{
			xtype:'CURDListTree',
			region: 'center',
			bind:{store:'{_MainStore}'},
			columns:[
				{xtype:"actioncolumn",header:"权限",width: 50,iconCls:'tf tf-edit',align:'center',handler: '_ColumnRule',bind:{hidden:'{!_Auth.rules}'}},
        		{xtype:"actioncolumn",header:"更新",width: 50,iconCls:'tf tf-edit',align:'center',handler: '_ColumnEdit',bind:{hidden:'{!_Auth.edit}'}},
				{xtype:"actioncolumn",header:"删除",width: 50,iconCls:'tf tf-del',align:'center',handler: '_ColumnDel',bind:{hidden:'{!_Auth.del}'}},
				{dataIndex:'id', header :'主键', width :60, hidden:false, },
				{dataIndex:'title', header :'标题',xtype : 'treecolumn', width :220, hidden:false },
				{dataIndex:'name', header :'路由', width :150, hidden:false },
				{dataIndex:'sort', header :'排序', width :60, hidden:false },
				{dataIndex:'identifying', header :'标志', width :200, hidden:false, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {return _Res_Val(_ExtendList,'extend', value);}},
				{dataIndex:'hide', header :'隐藏', width :60, hidden:false, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {return _Res_Val(_Dictionary,'sys_true', value);}},
				{dataIndex:'status', header :'状态', width :60, hidden:false, renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {return _Res_Val(_Dictionary,'sys_status', value);}},
				{dataIndex:'create_time', header :'创建时间', width :110, hidden:true },
				{dataIndex:'update_time', header :'更新时间', width :110, hidden:true },
			],
		},
		{xtype:'admin_AuthGroup_rules',region: 'east',bind:{hidden:'{!_Auth.rules}'},bind:{store:'{_RulesStore}'}}
	],
});

Ext.define('admin.auth_group.index_rules', {
    extend: 'Ext.tree.Panel',
	alias: 'widget.admin_AuthGroup_rules',
	width :320,
	style: 'border-top:1px solid #efefef;border-left:5px solid #eee;',
	rootVisible: false,
	useArrows: true,
    columns: [
		{dataIndex : "title",header: "节点", xtype : 'treecolumn',width:'100%'},
	],
	dockedItems: [
		{xtype: 'toolbar',dock: 'bottom',style: 'background:#5fa2dd',items: [
			'->',
			{xtype: 'button',text: '保存权限',handler: "_EditRule"},
		]}
	]
		
});


//操作 
Ext.define('admin.auth_group.updata', {
	extend: 'Tg.tx.Window',
	alias: 'widget.admin_AuthGroup_updata',
	requires: [
		'admin.auth_group.CURDViewController',
		'admin.auth_group.CURDViewModel',
	],
	controller: '_adminAuthGroupController',
	viewModel: '_adminAuthGroupViewModel',
    title:'角色 - 操作',
	width:400,
	height:250,
    items:{
    	xtype:'CURDForm',
        items:[
			{items: [
				{xtype:'treepicker', fieldLabel: '上级', name: 'p_id', itemId: 'p_id', cls: '', columnWidth: 1, height: 30, readOnly: false, emptyText:'请输入...', editable:false,displayField: "text",valueField: "id",rootVisible:true,store:Ext.create('Ext.data.TreeStore',{autoLoad: true,expanded:true,proxy : {type : 'ajax',url : _PATH['site']+'/admin/api/group_lists?verify_code={:_AutoCodeUrl('admin/Index/index')}'}})},
			]},
			{items: [
				{xtype:'textfield', fieldLabel: '标题', name: 'title', itemId: 'title', cls: '', columnWidth: 1, height: 30, readOnly: false, emptyText:'请输入...'},
			]},
			{items: [
				{xtype:'numberfield', fieldLabel: '排序', name: 'sort', itemId: 'sort', cls: '', columnWidth: .5, height: 30, readOnly: false, minValue:'0', maxValue:'999999', allowDecimals:false, decimalSeparator:'.'},
				{xtype:'combobox', fieldLabel: '状态', name: 'status', itemId: 'status', cls: '', columnWidth: .5, height: 30, readOnly: false, emptyText:'请选择', editable:false, displayField:'text', valueField: 'value', store:{fields:['text','value'],data:_Dictionary['sys_status']}},
			]},
			{xtype:'hiddenfield', fieldLabel: '主键', name: 'id', itemId: 'id', cls: '', columnWidth: 1, height: 30, readOnly: false},
        ]
    }
});

//实例化
Ext.application({
	name: 'admin',
	extend: 'Ext.app.Application',
	autoCreateViewport: 'admin.auth_group.index'
});
</script>
{/block}